package com.feilo.dao.impl;

import java.io.Serializable;
import java.util.List;

import com.feilo.dao.BaseDao;
import com.feilo.util.HibernateUtil;


public class BaseDaoImpl implements BaseDao {

	public <T> void delete(Class<T> entityClass, Serializable entityid) {
		HibernateUtil.del(HibernateUtil.get(entityClass, entityid));
	}

	public <T> void delete(Class<T> entityClass, Serializable[] entityids) {
		for(Serializable id:entityids){
			HibernateUtil.del(HibernateUtil.get(entityClass, id));
		}	
	}
	
	public void save(Object entity) {
		HibernateUtil.add(entity);
	}
	
	public void update(Object entity) {
		HibernateUtil.update(entity);
	}
	
	public <T> T find(Class<T> entityClass, Serializable entityid) {
		return HibernateUtil.get(entityClass, entityid);
	}

	@SuppressWarnings("unchecked")
	public Object findByHQL(String hql) {
		List<Object> obj=(List<Object>)HibernateUtil.findBySQL(hql);
		return obj;
	}

}
